Simple Sync 0.3.1: Take any number of folders and make them match up, by way of creating a new folder with the most up to date files in it.
Copyright (C) 1999 Gordon Worley.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
For a copy of the GNU General Public License, visit <http://www.gnu.org/> or write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330, Boston, MA 02111-1307, USA.
To contact me, please visit my Web site at <http://www.rbisland.cx/> or e-mail me at <redbird@rbisland.cx>.
History:
0.3.1 - Fixed the bug and bumped the number to reflect the fact that a few changes were made during the betas.
0.3b1 - Didn't fix the bug, thus the beta status. Did make the open handler work, though. Also changed 'me's' to 'my' to further promote English-like code.
0.3b0 - Much of the code has been changed around. Every thing seems to work now, but sometimes I get an error in sync() that I've noted below.
0.1.5 - Commented the code so that others will be able to make some sense out of it.
0.1 - Added support for resyncing the original folders used in making syncedFolder and deleting syncedFolder when done with it.
0.0 - Initial release.
*)
on run
try
set folder1 to choose folder with prompt "Choose first folder to sync:"
on error --user probably pressed cancle and wants to exit the program
return
end try
try
set folder2 to choose folder with prompt "Choose second folder to sync:"
on error
return
end try
my autoSync({folder1, folder2})
end run
on open theFolders
repeat with aFolder in theFolders
if alias (aFolder as string)'s kind is not "folder" then
display dialog "Sorry, but at least one of the objects you dropped on this application were not folders. Please try again with only folders." buttons "OK" default button 1
return
end if
my autoSync(theFolders)
end repeat
end open
on autoSync(theFolders)
try
tell application "Finder" to set syncedFolder to make folder with properties {name:"Synced Folder"}
on error
--this is usually because, as the dialog says, some folder named 'Synced Folder' already exist
--sometimes, though, it is because you have made a stupid mistake, like forgetting to *tell the Finder* to do the making of new folders
display dialog "Sorry, but a folder \"Synced Folder\" already exist. Move \"Synced Folder\" off the Desktop and then try again." buttons "OK" default button 1
return
end try
my sync(theFolders, syncedFolder)
my resync(theFolders, syncedFolder)
my cleanUp(syncedFolder)
end autoSync
on sync(theFolders, syncedFolder)
tell application "Finder"
repeat with aFolder in theFolders
--these next two lines make a list of everything (folder, file, application) in the respective folders
--note how below an alias must be built using the path to the folder that was gotten in the arguments and combining it with an item to form a full alias
set syncedFolderItems to list folder syncedFolder
set aFolderItems to list folder aFolder
repeat with anItem in aFolderItems
if anItem is not in syncedFolderItems then
duplicate alias ((aFolder as string) & anItem) to syncedFolder
else --anItem is not in syncedFolderItems
if alias ((aFolder as string) & anItem)'s kind is "folder" then
--note how ':' must be added after anItem so that it is a folder rather than a file when as an alias
my sync({(alias ((aFolder as string) & anItem & ":"))}, (alias ((syncedFolder as string) & anItem & ":")))
else if alias ((aFolder as string) & anItem)'s modification date > alias ((syncedFolder as text) & anItem)'s modification date then --use the newest one
duplicate alias ((aFolder as string) & anItem) to syncedFolder with replacing
end if
end if
end repeat
end repeat
end tell
end sync
on resync(theFolders, syncedFolder)
tell application "Finder"
repeat with aFolder in theFolders
--thanks to John Louch for helping with this part on the applescript-users mailing list
set aFolderName to aFolder's name
set syncedFolderToMove to duplicate syncedFolder
set parentFolder to syncedFolderToMove's container
set syncedFolderToMove's name to aFolderName
move parentFolder's folder aFolderName to aFolder's container with replacing